package com.lwj.controller.configuration;

import com.lwj.dto.configuration.*;
import com.lwj.dto.system.DictionaryCategoryDto;
import com.lwj.entity.RestEntity;
import com.lwj.model.configuration.DepartmentRole;
import com.lwj.service.configuration.PermissionService;
import com.lwj.vo.PageBean;
import com.lwj.vo.configuration.DepartmentRoleMenuVo;
import com.lwj.vo.configuration.RoleVo;
import com.lwj.vo.configuration.UserRoleVo;
import com.lwj.vo.system.MenuVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags ="权限接口")
@RestController()
@RequestMapping("/api/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @ApiOperation(value = "角色列表")
    @PostMapping("/role/list")
    public RestEntity<PageBean<RoleVo>> roleList(@RequestBody RoleListDto dto){
        return RestEntity.success(permissionService.roleList(dto));
    }
    @ApiOperation(value = "角色保存")
    @PostMapping("/role/save")
    public RestEntity<String> roleSave(@RequestBody DepartmentRoleDto dto){
        return RestEntity.success(permissionService.roleSave(dto));
    }

    @ApiOperation(value = "查询角色已有人员")
    @PostMapping("/getUserByRole")
    public RestEntity<PageBean<UserRoleVo>> gerUserByRole(@RequestBody UserRoleListDto dto){
        return RestEntity.success(permissionService.getUserByRole(dto));
    }
    @ApiOperation(value = "根据角色查询菜单树")
    @GetMapping("/menuTreeByRoleId")
    public RestEntity< List<DepartmentRoleMenuVo>> menuTreeByRoleId(@RequestParam("departmentRoleId") String departmentRoleId){
        return RestEntity.success(permissionService.menuTreeByRoleId(departmentRoleId));
    }
    @ApiOperation(value = "分配人员")
    @PostMapping("/addUserToRole")
    public RestEntity addUserToRole(@RequestBody UserRoleDto dto){
        permissionService.addUserToRole(dto);
        return RestEntity.success();
    }

    @ApiOperation(value = "删除角色人员")
    @GetMapping("/deleteUserRole")
    public RestEntity  deleteUserRole(@RequestParam("departmentRoleId") String departmentRoleId,@RequestParam("empId") String empId){
        permissionService.deleteUserRole(departmentRoleId,empId);
        return RestEntity.success();
    }
    @ApiOperation(value = "保存菜单权限")
    @PostMapping("/savePermission")
    public RestEntity savePermission(@RequestBody DepartmentRoleMenuDto dto){
        permissionService.savePermission(dto);
        return RestEntity.success();
    }
}
